package com.swpu.eduorder.service.impl;

import com.swpu.commonutils.CourseWebVoOrder;
import com.swpu.eduorder.OrderNoUtil;
import com.swpu.eduorder.clients.EduClient;
import com.swpu.eduorder.clients.UcenterClient;
import com.swpu.eduorder.entity.TOrder;
import com.swpu.eduorder.entity.UcenterMember;
import com.swpu.eduorder.mapper.TOrderMapper;
import com.swpu.eduorder.service.TOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author ygq
 * @since 2021-10-30
 */
@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService {
    @Autowired
    private EduClient eduClient;
    @Autowired
    private UcenterClient ucenterClient;
    @Override
    public String saveOrder(String courseId, String memberIdByJwtToken) {
        System.out.println("save");
        //通过远程调用获取用户信息 课程信息
        System.out.println(courseId+" "+memberIdByJwtToken );
        CourseWebVoOrder courseDto = eduClient.getInfo(courseId);
        System.out.println("Edu正常执行"+courseDto.toString());
        UcenterMember ucenterMember = ucenterClient.getMenm(memberIdByJwtToken);
//        创建order对象 并赋值
        //创建订单
        TOrder order = new TOrder();
        order.setOrderNo(OrderNoUtil.getOrderNo());
        order.setCourseId(courseId);
        order.setCourseTitle(courseDto.getTitle());
        order.setCourseCover(courseDto.getCover());
        order.setTeacherName("test");
        order.setTotalFee(courseDto.getPrice());
        order.setMemberId(memberIdByJwtToken);
        order.setMobile(ucenterMember.getMobile());
        order.setNickname(ucenterMember.getNickname());
        order.setStatus(0);
        order.setPayType(1);
        baseMapper.insert(order);
        return order.getOrderNo();
    }
}
